home *** CD-ROM | disk | FTP | other *** search
/ SunSoft Catalyst CDWARE 1996 May to August / Catalyst CDWARE 1996 May to August.iso / .products / .bin / httpd / Solaris_2 / newwais.pl.bk < prev    next >
Text File  |  1995-10-20  |  4KB  |  155 lines

  1. #!./perl
  2. #
  3. # newwais.pl -- WAIS search interface
  4. #
  5. # from wais.pl
  6. #
  7. # Tony Sanders <sanders@bsdi.com>, Nov 1993
  8. #
  9. # Example configuration (in local.conf):
  10. #     map topdir wais.pl &do_wais($top, $path, $query, "database", "title")
  11. #
  12. # this script uses a sneaky feature of Mosaic that interpretes a 
  13. # single text input form with the name 'isindex' (case sensitive) to
  14. # the same as a <ISINDEX>.  On non-mosaic clients, you wind up with an
  15. # additional query
  16. #
  17. # Note that I know even less about perl than the other two people
  18. # who hacked this, so feel free to send hate mail to pjh@netcom.com
  19. # if I did something really bad (or if there is a better way of
  20. # grabbing the filename off the end of a path.
  21. #
  22.  
  23. #require 'ctime.pl';
  24.  
  25. $waisq = "./waisq";
  26. $waisd = "/tmp/.wais/wais";
  27.  
  28.  
  29. $src = "catalyst_catalog";
  30. $title = "Example Data";
  31. #
  32. # file type map based on file extension, since all file types
  33. # come back type URL
  34. #
  35.  
  36. %filetype = (
  37. 'html', 'HTML File',
  38. );
  39.  
  40. #
  41. # code
  42.  
  43. sub send_index {
  44.     print "Content-type: text/html\n\n";
  45.     
  46.     print "<HEAD>\n<TITLE>Index of ", $title, "</TITLE>\n</HEAD>\n";
  47.     print "<BODY>\n<H1>", $title, "</H1>\n";
  48.  
  49.     print "This is an index of the information on this server. Please\n";
  50.     print "type a query in the search dialog.\n<P>";
  51.     print "You may use compound searches, such as: <CODE>environment AND cgi</CODE>\n";
  52.     print "<ISINDEX>";
  53. }
  54.  
  55. sub do_wais {
  56. #    local($top, $path, $query, $src, $title) = @_;
  57.  
  58. # strip the escape off of *'s
  59.     for (@ARGV){s/\\//g};
  60.  
  61.     do { &'send_index; return; } unless defined @ARGV;
  62.     local(@query) = @ARGV;
  63.     local($pquery) = join(" ", @query);
  64.     local($nquery) = $pquery;
  65.     $nquery =~ tr/[A-Z]/[a-z]/;
  66.     if (!(($nquery =~ / and /) || ($nquery =~ / or /)))
  67.     {
  68.        $nquery =~ s/ //g;
  69.     }
  70. #
  71. # grab a wais source if there is one
  72. #
  73.  
  74.     local($test) = $ENV{'PATH_INFO'};
  75.     if ($test)
  76.     {
  77.     $test =~ s/\///;
  78.         $src = "catalyst_catalog";
  79.         $title = $test;
  80.     }
  81.  
  82.     close STDERR;
  83.     open(STDERR, ">/dev/null");
  84.  
  85.     print "Content-type: text/html\n\n";
  86.  
  87.     $ENV{'HOME'} = "/";
  88.     
  89.     open(WAISQ, "-|") || exec ($waisq, "-c", $waisd, "-m", 200,
  90.                                 "-f", "-", "-S", "$src.src", "-g", $nquery);
  91.  
  92.     print "<HEAD>\n<TITLE>Search of ", $title, "</TITLE>\n</HEAD>\n";
  93.     print "<img src=\"/.wais/images/goto_home.gif\">\n";
  94.     print "<BODY>\n<H1>Catalyst Catalog on CDware</H1>\n";
  95.  
  96.     print "<HR><FORM method=\"POST\" action=\"/cgi-bin/newwais.pl/$src\">\n";
  97.     print "Enter keyword(s):\n";
  98. #    print "<input name=\"isindex\" value=\"@query\" size=30></FORM><HR>\n";
  99.     print "<input name=\"isindex\" value=\"$pquery\" size=30></FORM><HR>\n";
  100.  
  101.     print "$title contains the following\n";
  102.     print "items relevant to <B>\`$pquery\':</B><P>\n";
  103.     print "<DL>\n";
  104.  
  105.     local($hits, $score, $headline, $lines, $bytes, $type, $date);
  106.  
  107.     print "<OL>";
  108.     while (<WAISQ>) {
  109.         /:score\s+(\d+)/ && ($score = $1);
  110.         /:number-of-lines\s+(\d+)/ && ($lines = $1);
  111.         /:number-of-bytes\s+(\d+)/ && ($bytes = $1);
  112.         /:type "(.*)"/ && ($type = $1);
  113.         /:headline "(.*)"/ && ($headline = $1);         # XXX
  114.         /:date "(\d+)"/ && ($date = $1, $hits++, &docdone);
  115.     }
  116.     print "</OL>";
  117.     close(WAISQ);
  118.     print "</DL>\n";
  119.  
  120.     if ($hits == 0) {
  121.         print "Nothing found.\n";
  122.     }
  123.     print "</BODY>\n";
  124. }
  125.  
  126.  
  127. sub docdone {
  128.  
  129.     if ($headline =~ /Search produced no result/) {
  130.         print "<HR>";
  131.     print "Search produced no result.";
  132. #        print $headline, "<P>\n<PRE>";
  133. # the following was &'safeopen
  134. #        open(WAISCAT, "$waisd/$src.cat") || die "$src.cat: $!";
  135. #        while (<WAISCAT>) {
  136. #            s#(Catalog for database:)\s+.*#$1 <STRONG>Catalyst Catalog on CDware</STRONG>#;
  137. #            s#Headline:\s+(.*)#Headline: <A HREF="$1">$1</A>#;
  138. #            print;
  139. #        }
  140. #        close(WAISCAT);
  141. #        print "\n</PRE>\n";
  142.     } else {
  143.         $docname = $headline;
  144.     $docname =~ s/\.([^.]*)$//;
  145.     $extension= $1;
  146.     $docname =~ s/\/([^\/]*)$//;
  147.     $docname = $1;
  148.         print "<LI><A HREF=\"$headline\"><B>$docname</B></A>\n";
  149.     }
  150.     $score = $headline = $lines = $bytes = $type = $date = '';
  151. }
  152.  
  153. eval '&do_wais';
  154.